//---------------------------------------------------------------------
// Author: jachymko
//
// Description: Parameter name tab expansion handler tests
//
// Creation Date: Jan 19, 2007
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

using Pscx.Commands.TabExpansion;

namespace PscxUnitTests.TabExpansion
{
    [TestFixture]
    public class ParameterNameTest : TabExpansionTestBase
    {
        [Test]
        public void GetTabExpansionParams()
        {
            AssertExpansions("Get-TabExpansion -", "-", new string[]
            {
                "-Debug", 
                "-ErrorAction", 
                "-ErrorVariable",
                "-LastWord", 
                "-Line", 
                "-OutBuffer",
                "-OutVariable",
                "-Verbose"
            });
        }

        [Test]
        public void GetTabExpansionParamsPrefix()
        {
            AssertExpansions("Get-TabExpansion -L", "-L", new string[]
            {
                "-Line", "-LastWord"
            });
        }

        [Test]
        public void FormatListAlias()
        {
            AssertExpansions("fl -GroupB", "-GroupB", new string[]
            {
                "-GroupBy"
            });
        }

        [Test]
        public void FormatListStatementsAndBlocks()
        {
            AssertExpansions("{ dir; dir c:\\ }; (get-date); fl -p", "-p", new string[]
            {
                "-Property"
            });
        }

        [Test]
        public void FormatTableOpenParen()
        {
            AssertExpansions("(get-date); (ft -a", "-a", new string[]
            {
                "-AutoSize"
            });
        }

        [Test]
        public void FunctionParams()
        {
            Invoke("function f([string]$str, $var, $def = $(read-host -test @(\"brekeke\", $dzin)), [switch]$sw) { write-host guuu }");
            AssertExpansions("f -", "-", new string[]
            {
                "-str", "-var", "-def", "-sw"
            });
        }

        [Test]
        public void FunctionParamsPrefix()
        {
            Invoke("function g { param($ua, [long]$ub, $kkkk = 'aaaaa', $uc = @(1,2,3,4,5)) write-host huuu }");

            AssertExpansions("g -u", "-u", new string[]
            {
                "-ua", "-ub", "-uc"
            });
        }

#if ISPUBLIC_RemoveCommentsAndStrings
        [Test]
        public void RemoveCommentsAndStrings()
        {
            AssertCommentsAndStrings("$hello =  $null ;  $null ; ", "$hello = \"hello world\"; 'dzzz'; @\"here string");
            AssertCommentsAndStrings("write-host lalala ", "write-host lalala # komentar");
        }
        
        private void AssertCommentsAndStrings(string expected, string input)
        {
            Assert.AreEqual(expected, Utils.RemoveCommentsAndStrings(input));
        }
#endif
    }
}
